package com.heyou.ticket;

import org.springframework.ai.reader.TextReader;
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
import org.springframework.ai.vectorstore.VectorStore;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.core.io.Resource;

@SpringBootApplication
public class HeyouTicketApplication {

    public static void main(String[] args) {
        SpringApplication.run(HeyouTicketApplication.class, args);
    }

    // 检索增强生产环境初始化向量DB
    // @Bean
    public CommandLineRunner ingestRagVectorStore(VectorStore vectorStore,
                                                  @Value("classpath:static/rag/ticket-book.txt") Resource resource) {
        return args -> {
            vectorStore.write(                              // 3、写入
                    new TokenTextSplitter().transform(      // 2、分词
                            new TextReader(resource).read() // 1、读取
                    )
            );
        };
    }
}
